package com.example.yjhmatch.controller;


import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.example.yjhmatch.service.ITeamsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yc.yjh.entity.Result;
import com.yc.yjh.entity.Teams;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 队伍表 前端控制器
 * </p>
 *
 * @author 廖老师
 * @since 2023-07-18
 */
@RestController
@RequestMapping("/yjhteam/teams")
public class TeamsController {
    @Resource
    ITeamsService teamsService;
    @RequestMapping("selectTeam")
    public List selectTeam(){
        return teamsService.list();
    }

    @RequestMapping("orderByWin")
    public List orderByWin(){
        return teamsService.lambdaQuery().orderByDesc(Teams::getTotalWin).list();
    }
    @RequestMapping("selectAllTeams")
    public PageInfo<Teams> selectAllTeams(@RequestParam int current){
        //获取第1页，10条内容，默认查询总数count
        PageHelper.startPage(current, 3);
        List<Teams> list = teamsService.list();
        //用PageInfo对结果进行包装
        PageInfo page = new PageInfo(list);
        return page;
    }
    @RequestMapping("selectTeamsCount")
    public Long selectTeamsCount(){
        return teamsService.lambdaQuery().count();
    }
    @RequestMapping("selectTeamByName")
    public Result selectTeamByName(@RequestParam("name") String name){
        List<Teams> list;
        if (!name.trim().isEmpty()&&name!=""){
            list=teamsService.lambdaQuery().like(Teams::getName,name).list();
        }else {
            list=teamsService.list();
        }
        return Result.success("查询成功",list);
    }
}

